<?php

use \app\dao\WechatGroupChatMessageDO;

class WechatGroupChatMessageModel extends \app\model\BaseModel {

    protected $dbname = 'wechat';
    protected $tablename = 'wechat_group_chat_message';

    public static $STATE_UNREAD = 1;
    public static $STATE_READ = 2;

    public function insert(WechatGroupChatMessageDO $do) {
        $insertData = [];
        if (!$do->xiaou_id || !$do->friend_id || !$do->chatroom_id) {
            return outputObject(FALSE, '群聊消息关键信息为空');
        }

        foreach ($do as $_k => $_v) {
            if ($_k == 'id') {
                continue;
            }
            if (in_array($_k, ['msg_id', 'msg_type', 'msg_time', 'state', 'customer_type', 'send_type'])) {
                $insertData[$_k] = $_v === -1 ? 0 : intval($_v);
            } else {
                $insertData[$_k] = $_v ? trim($_v) : '';
            }
        }
        if (!$insertData) {
            return outputObject(FALSE, '群聊消息写入数据为空');
        }
        $insertData['gmt_create'] = $insertData['gmt_modified'] = time();
        return $this->_insert($insertData);
    }
}
